package com.contract.pojo.dto;

import com.contract.common.enums.SignTypeEnum;
import com.contract.common.util.CommonUtil;
import com.contract.common.util.Constant;
import lombok.Data;

import java.time.LocalDate;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author liw
 * @version 1.0
 * @date 2024/2/6 17:52
 */
@Data
public class ContractSignDto {

    private String fromPath;
    private String outPath;

    List<ImgInfo> imgInfoList;


    @Data
    public static class ImgInfo {
        private String type;
        private String value;
        private String key;
        private String imgPath;
        private int page;
        private int width;
        private int height;
        private int x;
        private int y;
    }

    public static void getValueTest(List<ImgInfo> list, String rootPath) {
        for (ContractSignDto.ImgInfo imgInfo : list) {
            if (SignTypeEnum.STAMP.getKey().equals(imgInfo.getType())) {
                if (CommonUtil.isEmpty(imgInfo.getImgPath())) {
                    imgInfo.setImgPath(rootPath + Constant.STAMP_PATH_TEST);
                }
            } else if (SignTypeEnum.CORPORATION.getKey().equals(imgInfo.getType())) {
                if (CommonUtil.isEmpty(imgInfo.getImgPath())) {
                    imgInfo.setImgPath(rootPath + Constant.CORPORATION_PATH_TEST);
                }
            }else   if (SignTypeEnum.USER.getKey().equals(imgInfo.getType())) {
                if (CommonUtil.isEmpty(imgInfo.getImgPath())) {
                    imgInfo.setImgPath(rootPath + Constant.USER_PATH_TEST);
                }
            } else if (SignTypeEnum.DATE.getKey().equals(imgInfo.getType())) {
                if (CommonUtil.isEmpty(imgInfo.getValue())) {
                    imgInfo.setValue(LocalDate.now().toString());
                }
            }
        }
    }

    public static void getValue(List<ImgInfo> list, String rootPath) {
        for (ContractSignDto.ImgInfo imgInfo : list) {
            if (SignTypeEnum.STAMP.getKey().equals(imgInfo.getType())) {
                if (CommonUtil.isEmpty(imgInfo.getImgPath())) {
                    imgInfo.setImgPath(rootPath + Constant.STAMP_PATH);
                }
            } else if (SignTypeEnum.CORPORATION.getKey().equals(imgInfo.getType())) {
                if (CommonUtil.isEmpty(imgInfo.getImgPath())) {
                    imgInfo.setImgPath(rootPath + Constant.CORPORATION_PATH);
                }
            }else if (SignTypeEnum.DATE.getKey().equals(imgInfo.getType())) {
                if (CommonUtil.isEmpty(imgInfo.getValue())) {
                    imgInfo.setValue(LocalDate.now().toString());
                }
            }
        }
    }

}
